package cn.xpf.study.model.vo;

import cn.xpf.study.model.Lesson;
import cn.xpf.study.model.LessonItem;
import cn.xpf.study.model.LessonItemContent;
import cn.xpf.study.utils.JsonUtil;
import cn.xpf.study.utils.TimeUtil;
import java.util.List;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * Create on 2021/5/15
 *
 * @author shuxinsheng@qiyi.com
 **/
@Data
@NoArgsConstructor
public class LessonVo {

    public int id;
    public int order;
    public String name;
    public String title;
    public String desc;
    public String image;
    public int status;
    public String rawContent;
    public List<LessonItemContent> content;
    public String create_time;
    public String update_time;

    public LessonVo(Lesson lesson, LessonItem lessonItem) {
        this.id = lesson.id;
        this.order = lesson.order;
        this.name = lesson.name;
        this.title = lesson.title;
        this.desc = lesson.desc;
        this.image = lesson.image;
        this.status = lesson.status;
        this.create_time = TimeUtil.getTimeStr(lesson.create_time);
        this.update_time = TimeUtil.getTimeStr(lesson.update_time);
        if (lessonItem != null) {
            this.content = JsonUtil.fromContent(lessonItem.getContent());
            if (this.content != null) {
                this.rawContent = JsonUtil.contentToJson(content);
            }
        }
    }

}
